package com.huwei.modules.base.constant;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.huwei.modules.base.util.StringUtil;

public class SystemConstant {

	static private Map<String, String> constantMap = new ConcurrentHashMap<String, String>();
	
	/**
	 * 	初始化系统参数
	 * @param constant
	 */
	static public void initialzeJsonResultConstant(Map<String ,String> constant) {
		constantMap = constant;
	}
	
	static public String secret() {
		return properties("secret");
	}
	
	static public String ip() {
		return properties("ip");
	}
	
	static public Integer port() {
		return StringUtil.stringToInteger(properties("port"));
	}
	
	static public String contextPath() {
		return properties("contextPath");
	}
	
	static public String webRoot() {
		String contextPath = contextPath();
		return "http://" + ip() + ":" + port() + (contextPath == null ? "/" : contextPath);
	}
	
	static public String properties(String key) {
		return properties(key, null);
	}
	
	static public String properties(String key ,String defaultValue) {
		String value = constantMap.get(key);
		return value == null ? defaultValue : value;
	}
}
